'''
用于将连续png图片合成视频
'''

import os
import cv2

import os

file_dir = r'E:\2023\项目\时空芯片\cell\resource\animation\image'
list = []
for root ,dirs, files in os.walk(file_dir):
    for file in files:
        list.append(file)      # 获取目录下文件名列表

video = cv2.VideoWriter(r'E:\2023\项目\时空芯片\cell\resource\animation\910all.avi',cv2.VideoWriter_fourcc(*'MJPG'),100,(1280,720))
list.sort(key=lambda x:int(x[5:-4]))
print(list)
for i in range(1,len(list)):

#     #读取图片

    img = cv2.imread(r'E:\2023\项目\时空芯片\cell\resource\animation\image/'+list[i-1])
    # print(r'E:\2023\项目\时空芯片\cell\resource\animation\1.ASC_275/'+list[i-1])
    # resize方法是cv2库提供的更改像素大小的方法
    # 将图片转换为1280*720像素大小
    img = cv2.resize(img,(1280,720))
#     # 写入视频
    video.write(img)
#
# # 释放资源
video.release()
# print('ok')